package com.weipai.springboot.base.interceptor;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 所有写的拦截器，必须要在这个类里面注册，否则没用
 */
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {

    @Autowired
    private LoginHandlerInterceptor loginHandlerInterceptor;
/*    @Bean
    public AppInterceptor appInterceptor() {
        return new AppInterceptor();
    }*/
    @Override
    public void addInterceptors(InterceptorRegistry registry) {

        //注册拦截器
        //springboot已经做好的静态资源映射
        /*registry.addInterceptor(new LoginHandlerInterceptor()).addPathPatterns("/**")
                .excludePathPatterns("/index.html","/","/user/login");*/

        //请求用时拦截器
        registry.addInterceptor(new ExcuteTimeInterceptor());
        /*registry.addInterceptor(loginHandlerInterceptor);*/

//                .excludePathPatterns("/user/login","/user/loginOut","/user/thirdPartyLogin", "/user/error","/sms/sendCode","/customer/register");


        

        ////注册加解密拦截器  (拦截所有已api开头的拦截器)
        //InterceptorRegistration ir = registry.addInterceptor(appInterceptor()).addPathPatterns("/api/**");
        //
        ////不拦截请求
        ////ir.excludePathPatterns("/test/test");


    }
}
